<
<style>
.demo-affix {
  padding: 0px 30px;
  float: right;
  z-index: 1001
}
</style>

<template>
  <div>
    <Affix :offset-top="100">
      <ButtonGroup class="demo-affix">
        <Button 
          type="info" 
          @click="assignOK"
        >保存</Button>
        <Button 
          type="ghost" 
          @click="assignCancel"
        >取消</Button>
      </ButtonGroup>
    </Affix>
    <Card :bordered="false">
      <p slot="title">{{ role.Name }}</p>
      <Tree 
        ref="roleTree" 
        :data="assignItem" 
        multiple 
        show-checkbox
      />
    </Card>

  </div>
</template>

<script>
export default {
  components: {},
  data() {
    return {
      loading: false, //数据刷新遮罩层
      role: this.$route.params.role,
      assignData: false,
      assignItem: [],
      checkAllGroup: this.getRescheked
    };
  },
  computed: {
    getRescheked() {
      return this.$refs.roleTree.getCheckedNodes();
    }
  },
  watch: {},
  mounted() {
    let self = this;
    self.getall();
  },
  methods: {
    getall() {
      this.$api.GetResByRole(this.role.Id).then(res => {
        if (!res.error) {
          console.log(res.Data);
          this.assignItem = res.Data.children;
          this.assignData = true;
        } else {
          this.$Message.error(res.message, 4);
        }
      });
    },
    assignOK() {
      let rdata = {};
      rdata["Roleid"] = this.role.Id;
      rdata["Resources"] = this.$refs.roleTree.getCheckedNodes();
      console.log(rdata);
      this.$api.AssignResources(rdata).then(res => {
        if (!res.error) {
          this.$Message.success(res.message);
          this.$router.push({
            name: "角色管理"
          });
        } else {
          this.$Message.error(res.message, 4);
        }
      });
    },
    assignCancel() {
      this.$router.push({
        name: "角色管理"
      });
    }
  },
};
</script>
